﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LGCourt.Logic.BLL;
using LGCourt.Logic.Common;
using LGCourt.Logic.NBL.DBEntities;

namespace lgweb.control.inside.department
{
    public partial class IntHeader : System.Web.UI.UserControl
    {
        private string deptCode = "";
        private string deptID = "0";
        private string menu = "0";
        
        protected void Page_Load(object sender, EventArgs e)
        {
            this.deptID = string.IsNullOrEmpty(Request.QueryString["deptid"]) ? "0" : Request.QueryString["deptid"].ToString();
            this.deptCode = string.IsNullOrEmpty(Request.QueryString["Code"]) ? "" : Request.QueryString["Code"].ToString();
            this.menu = string.IsNullOrEmpty(Request.QueryString["cate"]) ? "0" : Request.QueryString["cate"];
            SetMenu();
            SetClassName();
        }
        private void SetMenu()
        {
            this.hdindex.HRef = string.Format("/inside/intColumn/index.aspx?cate=0&deptid={0}&Code={1}", deptID, deptCode);
            this.hdoffice.HRef = string.Format("/inside/intColumn/notice.aspx?cate=1&deptid={0}&Code={1}", deptID, deptCode);
            this.hdinfo.HRef = string.Format("/inside/intColumn/list.aspx?cate=2&deptid={0}&Code={1}", deptID, deptCode);
            this.hdnews.HRef = string.Format("/inside/intColumn/list.aspx?cate=3&deptid={0}&Code={1}", deptID, deptCode);
            
            this.hdwenhua.HRef = string.Format("/inside/intColumn/list.aspx?cate=4&deptid={0}&Code={1}", deptID, deptCode);
            this.hdshiping.HRef = string.Format("/inside/intColumn/list.aspx?cate=5&deptid={0}&Code={1}", deptID, deptCode);

            switch (this.menu)
            {
                case "0":
                    this.hdindex.Attributes.Add("class", "current");
                    break;
                case "1":
                    this.hdoffice.Attributes.Add("class", "current");
                    break;
                case "2":
                    this.hdinfo.Attributes.Add("class", "current");
                    break;
                case "3":
                    this.hdnews.Attributes.Add("class", "current");
                    break;                
                case "4":
                    this.hdwenhua.Attributes.Add("class", "current");
                    break;
                case "5":
                    this.hdshiping.Attributes.Add("class", "current");
                    break;
                default:
                    this.hdindex.Attributes.Add("class", "current");
                    break;
            }
        }
        private void SetClassName()
        {
            ColInfo colInfoBLL = new ColInfo();
            DeptClassCondition param = new DeptClassCondition();
            param.Name = "监察室栏目";
            List<V_DICT_SOURCE> classInfoList = colInfoBLL.GetDeptSourceList(param);
            this.hdinfo.InnerText = classInfoList.Count >= 1 ? classInfoList[0].Source : "工作动态";
            this.hdnews.InnerText = classInfoList.Count >= 2 ? classInfoList[1].Source : "廉政要闻";
            this.hdwenhua.InnerText = classInfoList.Count >= 3 ? classInfoList[2].Source : "政策法规";
            this.hdshiping.InnerText = classInfoList.Count >= 4 ? classInfoList[3].Source : "警钟长鸣";

            param = new DeptClassCondition();
            string deptName = "";
            if (deptID == "0")
            {
                DepartmentHandler departmentHandler = new DepartmentHandler();
                Department department = departmentHandler.GetDepartmentInfo(deptCode);
                 if (department != null)
                {
                    
                    deptName = department.Name;
                }
                //根据名称取部门ID
                param.Source = deptName;   
            }
            else
            {
                param.ClassID = int.Parse(deptID);
            }
            param.Name = "部门";
            V_DICT_SOURCE deptInfo = colInfoBLL.GetDeptSourceInfo(param);
            if (deptInfo == null)
            {
                deptInfo = new V_DICT_SOURCE();
                deptInfo.ID = 1;
            }
            deptID = deptInfo.ID.ToString();
            DeptCondition deptParam = new DeptCondition();
            deptParam.DeptID = deptInfo.ID.GetValueOrDefault(0);
            LGFY_Platform_Index deptIndex = colInfoBLL.GetDeptIndexInfo(deptParam);
            spInfoEditer.InnerText = deptIndex == null ? "" : deptIndex.Managers;
        }
    }
}